package org.bendev.ildaplayer;


public abstract class AbstractPlayer implements Player {
	PlayerListener listener;
	Timer positionTimer = new Timer( 100, new Runnable(){ public void run(){ onPositionChange(); } } );

	@Override
	public void setListener( PlayerListener listener ){
		this.listener = listener;
	}
	
	void onStateChange(){
		State state = getState();
		if( listener!=null ) listener.onStateChange( state );
		if( state==State.PLAYING )
			positionTimer.start();
		else
			positionTimer.stop();
	}
	
	void onPositionChange(){
		if( listener!=null ) listener.onPositionChange( getPosition() );
	}
}
